Introduction

Delphi Source formatting Wizard is a customizable source code formatter. It can improve the indentation, spacing, capitalization and the use of blank lines of Delphi 5.0 source code. To do so the source code is parsed and lots of special constructs are tested. At default, the style of the Borland source code is followed closely, since this is the most widely accepted style. But formatting of Pascal code is much a matter of taste and debate. Therefore, some alternative rules are included.

The convenient interface, similar to standard Wizards in a Windows, possibility of saving of the several configurations, many customized parameters of formatting and to that similar trifles, will allow you to result in one sort source texts of your programs easily and simply.

Delphi Source formatting Wizard is available as Delphi 5 expert. It can process current file, all opened files, whole project or whole project group.

After installation, You can find our wizard in Delphi menu at Tools/Format Source Code.


Limitations and known problems

·	Compiler {$IFDEF} + {$ELSE} directives may be nested to 3 levels and break into blocks of code. After the third nested level the right indentation is not guaranteed.

·	After some options (aligning, adding line breaks) the indentation might be not correct. Rerunning Delphi Source formatting Wizard can fix the problems.

·	It is tried to indent function directives after function declarations. In some cases this does not happen.

·	No undo available. Close without saving to undo the formatting. When formatting a whole project backup files are created (*.~pas)


License
SOFTWARE LICENSE

Trial Version

    The trial version of this software may be used for evaluation purposes at the user's own risk for a period of 30 days from the date of installation. At the end of the trial period, the user must either purchase a license to continue using the software, or remove it from his/her system.

    The trial version may be freely distributed, provided the distribution package is not modified. No person or company may charge a fee for the distribution of Delphi Source formatting Wizard without written permission from the copyright holder.

Licensed Version

    On payment of the appropriate license fee, the user is granted a non-exclusive license to use Delphi Source formatting Wizard on one computer (i.e. a single CPU), for any legal purpose, at a time. The registered software may not be rented or leased, but may be permanently transferred, if the person receiving it agrees to terms of this license. If the software is an update, the transfer must include the update and all previous versions.

    Whilst every care has been taken in the construction and testing of this software, it is supplied subject to the condition that the user undertakes to evaluate the suitability of the control for his/her purposes. SDMSoft makes no representation of the software's suitability for any purpose, and the user agrees that SDMSoft has no responsibility for any loss or damage occasioned by the use of this software.

    TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" AND SDMSOFT DISCLAIMS ALL OTHER WARRANTIES AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, CONFORMANCE WITH DESCRIPTION, TITLE AND NON-INFRINGEMENT OF THIRD PARTY RIGHTS.

    TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL SDMSOFT BE LIABLE FOR ANY INDIRECT, INCIDENTAL, CONSEQUENTIAL, SPECIAL OR EXEMPLARY DAMAGES OR LOST PROFITS WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE PRODUCT, EVEN IF SDMSOFT HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN ANY CASE, SDMSOFT'S CUMULATIVE AND ENTIRE LIABILITY TO YOU OR ANY OTHER PARTY FOR ANY LOSS OR DAMAGES RESULTING FROM ANY CLAIMS, DEMANDS OR ACTIONS ARISING OUT OF OR RELATING TO THIS AGREEMENT SHALL NOT EXCEED THE PURCHASE PRICE PAID FOR THIS LICENSE.

    Should any term of these terms and conditions be declared void or unenforceable by any court of competent jurisdiction, such declaration shall have no effect on the remaining terms hereof.

    If you do not agree to these conditions you should not install this software.


Registering SourceWizard

You may try out Delphi Source formatting Wizard without any costs for the period of one month. If you wish to keep on using it after one month, you have to register it with the author and pay a registration fee.

Once you have registered, you will receive a personal registration key that you can enter into the program so it knows that you have registered.

You may enter this key in exactly one (1) copy of Delphi Source formatting Wizard, installed on a single computer.

More than one person is allowed to use the software, as long as no two people use it at the same time. Just like a book can be read by many people, but only by one person at a time.

You may install the registered version of Delphi Source formatting Wizard on more than one computer if and only if you will be the only person using Delphi Source formatting Wizard. Otherwise, you will have to purchase a license for each machine.

If more than one person needs to use the software at the same time, you have to register a copy for each of them. Site licenses are available.

When new versions of Delphi Source formatting Wizard are released, you will be able to download them from sdmsoft.com.  Your Delphi Source formatting Wizard license will be valid for all future versions of Delphi Source formatting Wizard.

For Delphi Source formatting Wizard pricing info and offline (non-Internet) and online ordering methods, please visit http://www.sdmsoft.com/ where you will find all the information that you need.  If you would still have any questions, send an email to sales@sdmsoft.com.


Select format configuration

On this tab You can select one from already defined configurations ( see 'Defined configuration' )

or create new, based on one of already defined (see 'New configuration').

Set check on checkbox 'Modify selected configuration', if You want change some parameters of already defined configuration.


Select configuration
Select already defined configuration


Modify selected configuration
Edit selected configuration


New configuration
Create new configuration based on already defined


Configure indents

On this tab You can specify indent settings in Your source code.

•	Number of spaces per indent - defines the number of spaces per indent. In all situations the same amount of spaces is used.

•	Extra indent after begin or try - if checked an extra indent is added after if-then-else, with-do, on-exception-do and while-do statements:

with extra indent:

if i > 10 then

  begin

    l := 3;

  end

else

  begin

    l := 0;

  end;

no extra indent (default):

if i > 10 then

begin

  l := 3;

end

else

begin

  l := 0;

end;

•	Extra indent after "else" in "try" block - If checked an extra indent is added after "else" in the following kind of "try" block:

Without option:

  try

   DoRun;

  except

    on ESomeException do raise;

    on ESomeOtherException do raise;

  else

    ShowMessage('');

  end;

With option:

  try

   DoRun;

  except

    on ESomeException do raise;

    on ESomeOtherException do raise;

    else

  	 ShowMessage('');

  end;

•	Extra indent after "else" in "case" block - If checked an extra indent is added after "else" in the "do case" statement:

Without option:

  case i of

    someValue1:

      DoSomething1;

    someValue2:

      DoSomeThing2;

  else

    DoSomeThingElse;

  end;

   With option:

  case i of

    someValue1:

      DoSomething1;

    someValue2:

      DoSomeThing2;

    else

      DoSomeThingElse;

  end;

•	Never indent else if - With this option checked, the indent never increases after else if . The default behavior is that the indent only increases if there is a line feed between "if" and "else"

Without option:

  if t then

    k

  else

    if t then

      j;

   With option:

  if t then

    k

  else

  if t then

    j;

•	Indent comments - If this option is checked comments are aligned with the surrounding text, else comments remain unchanged.

 With indent comments

  if t then

  begin

          {this is

             a comment

          }

     j;

  end;

  becomes:

 if t then

 begin

   {this is

      a comment

   }

   j;

 end;

•	Indent compiler directives - If this option is checked compiler directives are aligned with the surrounding text, else compiler directives are not indented.

With indent compiler directives

 if t then

 begin

         {$IFDEF debug}

    j;

      {$ENDIF}

 end;

  becomes:

 if t then

 begin

   {$IFDEF debug}

   j;

   {$ENDIF}

 end;

  if this option is unchecked the result is:

 if t then

 begin

 {$IFDEF debug}

   j;

 {$ENDIF}

end;


Space per indent
Defines the number of spaces per indent. In all situations the same amount of spaces is used.


Extra indent after begin or try
If checked an extra indent is added after if-then-else, with-do, on-exception-do and while-do statements:

•	with extra indent:

if i > 10 then

  begin

    l := 3;

  end

else

  begin

    l := 0;

  end;

•	no extra indent (default):

·

if i > 10 then

begin

  l := 3;

end

else

begin

  l := 0;

end;


Extra indent after "else" in "try" block
If checked an extra indent is added after "else" in the following kind of "try" block:

•	Without option:

  try

   DoRun;

  except

    on ESomeException do raise;

    on ESomeOtherException do raise;

  else

    ShowMessage('');

  end;

•	With option:

  try

   DoRun;

  except

    on ESomeException do raise;

    on ESomeOtherException do raise;

    else

  	 ShowMessage('');

  end;


Extra indent after "else" in "case" block
If checked an extra indent is added after "else" in the "do case" statement:

•	Without option:

  case i of

    someValue1:

      DoSomething1;

    someValue2:

      DoSomeThing2;

  else

    DoSomeThingElse;

  end;

•	With option:

  case i of

    someValue1:

      DoSomething1;

    someValue2:

      DoSomeThing2;

    else

      DoSomeThingElse;

  end;


Never indent else if
With this option checked, the indent never increases after else if . The default behavior is that the indent only increases if there is a line feed between "if" and "else"

•	Without option:

  if t then

    k

  else

    if t then

      j;

•	With option:

  if t then

    k

  else

  if t then

    j;


Indent comments
If this option is checked comments are aligned with the surrounding text, else comments remain unchanged.

With indent comments

  ιφ τ τηεν

  βεγιν

          {τηισ ισ

             α χομμεντ

          }

     ϕ;

  ενδ;

becomes:

  ιφ τ τηεν

  βεγιν

    {τηισ ισ

       α χομμεντ

    }

    ϕ;

  ενδ;


Indent compiler directives
If this option is checked compiler directives are aligned with the surrounding text, else compiler directives are not indented.

With indent compiler directives

ιφ τ τηεν

βεγιν

        {∃ΙΦΔΕΦ δεβυγ}

   ϕ;

     {∃ΕΝΔΙΦ}

ενδ;

becomes:

ιφ τ τηεν

βεγιν

  {∃ΙΦΔΕΦ δεβυγ}

  ϕ;

  {∃ΕΝΔΙΦ}

ενδ;

if this option is unchecked the result is:

ιφ τ τηεν

βεγιν

{∃ΙΦΔΕΦ δεβυγ}

  ϕ;

{∃ΕΝΔΙΦ}

ενδ;


Configure Spaces

Configure Spacing

In this tab sheet you can define the spacing of various operators.

The spacing of each operator has four values:

None	No spaces round the operator	1+1

Before only	Only spaces before the operator	1 +1

After only	Only spaces after the operator	1+ 1

Before and after	Spaces around the operator	1 + 1

The operators are grouped in the following way:

Equals	:=

Math	+ - / * < > = and as div downto in is or shl shr xor

Colon	:

Comma	,

Left parenthesis	(

Right parenthesis	)

Left bracket	[

Right bracket	]


Configure Line breaks

On this page You can specify line break rules.

•	After "var", "type" etc.

procedure Test(var i: Integer; const t: Byte);

  var t: Integer;

  type Pword = ^Word;

becomes:

procedure Test(var i: Integer; const t: Byte);

  var

    t: Integer;

  type

    Pword = ^Word;

•	Before "end"

if i > 10 then

begin

  l :=3; end;

becomes:

if i > 10 then

begin

  l :=3;

end;

•	After semi colons (except directives)

·	·

if i > 10 then

begin

  l :=3; k := 3; s:=3;

end;

becomes:

if i > 10 then

begin

  l :=3;

  k := 3;

  s:=3;

end;

Note: no lines are added after directives like virtual, abstract, message. A construct like

procedure test(k: integer; l: word); forward;

remains unchanged.

•	Between else and if - Add line between else and if.

Note that this option is opposite to the After then option. Check the Never indent else if option to prevent indenting.

•	After "then","else","do",":", except single lines

if i > 10 then l :=3 else if t=0 then  k := 3;

for i:=0 to count-1 do inc(k);

becomes

if i > 10 then

    l :=3

  else if t=0 then

    k := 3;

for i:=0 to count-1 do

  inc(k);

The option is conservative: Single lines after if then, on ":" are NOT processed:

if i > 10 then  l := 3;

case i of

  1: t := 0;

  2: t := 3;

end;

Use the Wrap long lines option to break large if then statements. (Wrap text breaks text on then or do if possible).

Note that the lines are not removed if this option in unchecked, therefore it is irreversible.

•	Never before then and  do

if i > 10

  then

  l := 3;

becomes

if i > 10 then

  l := 3;

Note: if the Wrap Long lines option is checked then still might be moved to a single line.

•	Between every unit in "uses"

uses unit1, unit2, unit3;

becomes

uses

  unit1,

  unit2,

  unit3;

•	Remove double blank lines - check this option to remove all double (or more) blank lines. At most one blank line is then allowed

•	Wrap long lines - It is possible to let SourceWizard break long lines into smaller ones. If a formatted line is longer than the Wrap position, it is tried to break it in smaller lines. If the long line contains then, else or do, the line is broken on that reserved word, otherwise a line feed added after the rightmost space.  Lines without spaces and comments are not changed.

Note: the wrapped lines are not always indented correctly. Rerun SourceWizard to correct this.

•	Blank lines - Optionally blank lines can be added after main procedures or local procedures.

•	Begin style

1.	unchanged

2.	hanging after then, else do :

3.	breaks before and after

The code:

if i > 10 then begin l :=3

end;

stays the same if option 1 is selected.

If option 2 -  hanging is checked:

if i > 10 then begin

  l :=3

end;

 3. breaks before and after:

if i > 10 then

begin

  l :=3

end;


After "var", "type" etc
procedure Test(var i: Integer; const t: Byte);

  var t: Integer;

  type Pword = ^Word;

βεχομεσ:

procedure Test(var i: Integer; const t: Byte);

  var

    t: Integer;

  type

    Pword = ^Word;


Before "end"
if i > 10 then

begin

  l :=3; end;

becomes:

if i > 10 then

begin

  l :=3;

end;


After semi colons (except directives)
if i > 10 then

begin

  l :=3; k := 3; s:=3;

end;

βεχομεσ:

if i > 10 then

begin

  l :=3;

  k := 3;

  s:=3;

end;

Νοτε: νο λινεσ αρε αδδεδ αφτερ διρεχτιϖεσ λικε ϖιρτυαλ, αβστραχτ, μεσσαγε. Α χονστρυχτ λικε

procedure test(k: integer; l: word); forward;

ρεμαινσ υνχηανγεδ.


Between else and if
Add line between else and if.

Note that this option is opposite to the After then option. Check the Νεϖερ ινδεντ ελσε ιφ option to prevent indenting.


After "then","else","do",":", except single lines
if i > 10 then l :=3 else if t=0 then  k := 3;

for i:=0 to count-1 do inc(k);

βεχομεσ

if i > 10 then

    l :=3

  else if t=0 then

    k := 3;

for i:=0 to count-1 do

  inc(k);

Τηε οπτιον ισ χονσερϖατιϖε: Σινγλε λινεσ αφτερ ιφ τηεν, ον ":" are NOT processed:

if i > 10 then  l := 3;

case i of

  1: t := 0;

  2: t := 3;

end;

Use the Wrap long lines option to break large if then statements. (Wrap text breaks text on then or do if possible).

Note that the lines are not removed if this option in unchecked, therefore it is irreversible.


Never before then and  do
if i > 10

  then

  l := 3;

βεχομεσ

if i > 10 then

  l := 3;

Νοτε: ιφ τηε Wrap Long lines οπτιον ισ χηεχκεδ τηεν στιλλ μιγητ βε μοϖεδ το α σινγλε λινε.


Between every unit in "uses"
uses unit1, unit2, unit3;

βεχομεσ

uses

  unit1,

  unit2,

  unit3;


Remove double blank lines
Check this option to remove all double (or more) blank lines. At most one blank line is then allowed.


Wrap long lines
It is possible to let ΣουρχεΩιζαρδ break long lines into smaller ones.

If a formatted line is longer than the Wrap position, it is tried to break it in smaller lines. If the long line contains then, else or do, the line is broken on that reserved word, otherwise a line feed added after the rightmost space.  Lines without spaces and comments are not changed.

Note: the wrapped lines are not always indented correctly. Rerun ΣουρχεΩιζαρδ to correct this.


Blank lines after main procedures/functions
Optionally blank lines can be added after main procedures or local procedures.


Begin style
1.	unchanged

2.	hanging after then, else do :

3.	breaks before and after

The code:

if i > 10 then begin l :=3

end;

stays the same if option 1 is selected.

If option 2 −  hanging is checked:

if i > 10 then begin

  l :=3

end;

 3. breaks before and after:

if i > 10 then

begin

  l :=3

end;


Configure Capitalization

On this page You can define how format compiler directives and reserved words, etc.

•	Reserved words/Standard directives - The reserved words and standard directives can be written in:

1. lower case

2. UPPER CASE

3. First Character Uppercase

4. remain unchanged.

Note: that after one of the first three options is chosen the forth option has no effect anymore. Use the File with user defined capitalization option if you want different capitalization for some reserved words.

If standard directives are used as identifier, in most cases the capitalization is unchanged (the program may fail to recognize the context).

•	Compiler directives - The compiler directives {$XXX} can optionally be placed in upper case. This option is irreversible.

•	(Hex) numbers - The hexadecimal numbers and the exponent (E) of real numbers can optionally be placed in upper case. This option is irreversible.

•	File with user defined capitalization - This file contains identifiers and other word that are always written the same way.

The file is a text file with words on single lines. Example of the content of such file:

True

False

OnClick

Using this file

i := TRUE;

is always replaced with

i:= True;

The file can be created manual or automatically. If there are reserved words included in the file, the Capitalization of reserved words option is always overridden by this option.

•	CAP file using - CAP file usingapitalization  file can be used in different ways:

•	Do not use file: Nothing happens

•	Add new words only: With the option Add new words only mode the file is filled automatically with all new identifiers that the program encounters. In this mode all words in the code remain unchanged.

•	Use file: In this mode the capitalization of all words is changed according to the notation in the capitalization file. If there are reserved words or standard directives  included in the file, the notation of the file is always used.

•	Use file (except standard directives): This option is the same as the previous one except that  standard directives are only changed if these are used as identifiers: e.g.

PriVate

  property PriVate: Boolean; read FPrivate write FPrivate;

changes in:

private

   property Private: Boolean; read FPrivate write FPrivate;

if Private is included in the capitalization file and Standard directives are set to lower case

•	Add and use: This mode is a combination of Add new words mode and the Use file mode. New words are added automatically.

•	Add and use (except standard directives): This mode is a combination of Add new words mode and the Use file (except standard directives) mode.

With the option Add new words modes the file is filled automatically with all new identifiers that the program encounters. In this mode all words remain unchanged.  After editing the file, the Add new words mode should be unchecked to make it work.

Words that should not be changed in the text can best be commented out by adding '*' before them, e.g.:

*i

*nI

True

False

The words with a proceeding '*' are not changed in the text. In advantage over deleting is that the Add words mode doesn't add these outcommented words.

•	Edit user defined capitalization - when checked, allow edit capitaliation file.


Reserved words/Standard directives
The reserved words and standard directives can be written in:

1. lower case

2. UPPER CASE

3. First Character Uppercase

4. remain unchanged.

Note: that after one of the first three options is chosen the forth option has no effect anymore. Use the File with user defined capitalization option if you want different capitalization for some reserved words.

If standard directives are used as identifier, in most cases the capitalization is unchanged (the program may fail to recognize the context).


Compiler directives
The compiler directives {$XXX} can optionally be placed in upper case. This option is irreversible.


(Hex.) numbers (e.g. $FF, 1E10)
The hexadecimal numbers and the exponent (E) of real numbers can optionally be placed in upper case. This option is irreversible.


File with user defined capitalization
This file contains identifiers and other word that are always written the same way.

The file is a text file with words on single lines. Example of the content of such file:

Τρυε

Φαλσε

ΟνΧλιχκ

Using this file

ι := ΤΡΥΕ;

is always replaced with

ι:= Τρυε;

The file can be created manual or automatically. If there are reserved words included in the file, the Capitalization of reserved words option is always overridden by this option.


CAP file using
CAP file usingapitalization  file can be used in different ways:

•	Do not use file: Nothing happens

•	Add new words only: With the option Add new words only mode the file is filled automatically with all new identifiers that the program encounters. In this mode all words in the code remain unchanged.

•	Use file: In this mode the capitalization of all words is changed according to the notation in the capitalization file. If there are reserved words or standard directives  included in the file, the notation of the file is always used.

•	Use file (except standard directives): This option is the same as the previous one except that  standard directives are only changed if these are used as identifiers: e.g.

PriVate

  property PriVate: Boolean; read FPrivate write FPrivate;

changes in:

private

   property Private: Boolean; read FPrivate write FPrivate;

if Private is included in the capitalization file and Standard directives are set to lower case

•	Add and use: This mode is a combination of Add new words mode and the Use file mode. New words are added automatically.

•	Add and use (except standard directives): This mode is a combination of Add new words mode and the Use file (except standard directives) mode.

·

With the option Add new words modes the file is filled automatically with all new identifiers that the program encounters. In this mode all words remain unchanged.  After editing the file, the Add new words mode should be unchecked to make it work.

Words that should not be changed in the text can best be commented out by adding '*' before them, e.g.:

*i

*nI

True

False

The words with a proceeding '*' are not changed in the text. In advantage over deleting is that the Add words mode doesn't add these outcommented words.


Edit user defined capitalization
When checked, allow edit capitaliation file.


Configure Aligns

•	Align simple end of line comments - simple end of line comments are comments that are one line, with proceeding code. It can be aligned to a certain position (if possible). E.g.

var

   i:integer; //comm

   j{comm.}:integer; {comm.}

   toooooooooooooooo, long:integer; {comm.}

   {comm.}

changes in (position = 30):

var

  i: integer;                //comm

  j: {comm.} integer;        {comm.}

  toooooooooooooooo, long: integer; {comm.}

  	     {comm.}

•	Align var/const - var and const declarations can be aligned in the same way as comments: e.g.

const

   i =0;

var

  j:integer;

  toooooooooooooooooooo, long:integer;

changes in (position = 30):

const

  i                          = 0;

var

  j                          : integer;

  toooooooooooooooooooooo, long: integer;


Align simple end of line comments
Simple end of line comments are comments that are one line, with proceeding code. It can be aligned to a certain position (if possible). E.g.

ϖαρ

   ι:ιντεγερ; //χομμ

   ϕ{χομμ.}:ιντεγερ; {χομμ.}

   τοοοοοοοοοοοοοοοο, λονγ:ιντεγερ; {χομμ.}

   {χομμ.}

changes in (position = 30):

ϖαρ

  ι: ιντεγερ;                //χομμ

  ϕ: {χομμ.} ιντεγερ;        {χομμ.}

  τοοοοοοοοοοοοοοοο, λονγ: ιντεγερ; {χομμ.}

  	     {χομμ.}


Align var/const statements
Var and const declarations can be aligned in the same way ασ χομμεντσ: e.g.

const

   i =0;

var

  j:integer;

  toooooooooooooooooooo, long:integer;

changes in (position = 30):

const

  i                          = 0;

var

  j                          : integer;

  toooooooooooooooooooooo, long: integer;


Configure Miscalleous options

•	Directives in source to prevent formatting - to prevent the formatter from formatting a block of text use the directives.

Default:

{(*}

... block of code that remains unchanged ...

{*)}

You can change the default directives in any other codes (start not necessarily different from end). Of course, the directives should be a Delphi comment.

•	Menu shortcut - here You can specify menu shortcut for calling Delphi Source formatting Wizard.

·


Directives in source to prevent formatting
To prevent the formatter from formatting a block of text use the directives.

Default:

{(*}

... block of code that remains unchanged ...

{*)}

You can change the default directives in any other codes (start not necessarily different from end). Of course, the directives should be a Delphi comment.


Format range

The following buttons can be applied:

•	Current File: The file in the active window is formatted.

•	All opened Files: All opened files that belong to the current project are formatted.

•	All files in project: All files in the current project are formatted. From the files that are not opened, backups are created (*.~pas). Obviously it is recommended to backup the project first.

•	All files in project groupt: All files in the current project group are formatted. From the files that are not opened, backups are created (*.~pas). Obviously it is recommended to backup the project first.